//
//  OrderDetails.swift
//  Fancyswap
//
//  Created by Cheikh Bara on 2015-04-19.
//  Copyright (c) 2015 Jonathan Muschalle. All rights reserved.
//

import UIKit

class OrderDetails {
    
    var id:             Int       = 0
    var item:           OrderItem = OrderItem()
    
    var thumbnail:      UIImage?
    
    var status:         Int       = 0
    var amount:         Int       = 0
    var shippingFee:    Int       = 0
    var totalAmount:    Int       = 0
    var fromUser:       String    = ""
    var toUser:         String    = ""
    var userBalance:    Int       = 0
    
    var address:        OrderAddress = OrderAddress()
    
    init(id: Int, item: OrderItem, status: Int, amount: Int, shippingFee: Int, totalAmount: Int, fromUser: String, toUser: String, userBalance: Int, address: OrderAddress){
        self.id          = id
        self.item        = item
        self.status      = status
        self.amount      = amount
        self.shippingFee = shippingFee
        self.totalAmount = totalAmount
        self.fromUser    = fromUser
        self.toUser      = toUser
        self.userBalance = userBalance
    }
    
    init(){}
    
    
    init(dic: NSDictionary) {
        for elem in dic {
            switch (elem.key as String) {
                case "id":          self.id          = elem.value as Int
                case "status":      self.status      = elem.value as Int
                case "amount":      self.amount      = elem.value as Int
                case "shippingFee": self.shippingFee = elem.value as Int
                case "totalAmount": self.totalAmount = elem.value as Int
                case "fromUser":    self.fromUser    = elem.value as String
                case "toUser":      self.toUser      = elem.value as String
                case "userBalance": self.userBalance = elem.value as Int
                case "item":        self.item        = OrderItem(dic: (elem.value as NSDictionary) )
                case "address":     self.address     = OrderAddress(dic: (elem.value as NSDictionary) )
                default:            println("Unknown element: \(elem.key as String)")
            }
        }
    }
    
}
